using System;
using System.Windows;
using System.Windows.Forms.Integration;
using Microsoft.Practices.Prism.Commands;
using Microsoft.Reporting.WinForms;
using System.Data.SqlClient;

namespace ZhiHeng.OneCard.WpfClient.ViewModel
{
    public abstract class ReportFrameViewModel : ViewModelBase
    {
        private WindowsFormsHost _viewer = new WindowsFormsHost();

        public WindowsFormsHost Viewer
        {
            get { return _viewer; }
            set
            {
                this.SetPropertyValue(value, ref _viewer, "Viewer");
            }
        }

        private DateTime _endDay = DateTime.Now;
        /// <summary>
        /// EndDay
        /// </summary>
        public DateTime EndDay
        {
            get
            {
                return _endDay;
            }
            set
            {
                _endDay = value;
                this.RaisePropertyChanged("EndDay");
            }
        }


        private DateTime _startDay = DateTime.Now;
        /// <summary>
        /// Start Day
        /// </summary>
        public DateTime StartDay
        {
            get
            {
                return _startDay;
            }
            set
            {
                _startDay = value;
                this.RaisePropertyChanged("StartDay");
            }
        }
        

        private DelegateCommand _query;
        /// <summary>
        /// Query   
        /// </summary>
        public DelegateCommand Query    
        {
            get
            {
                return _query ?? (_query = new DelegateCommand(() =>
                {
                    ReportViewer reportViewer = new ReportViewer();
                    reportViewer.ProcessingMode = ProcessingMode.Local;

                    PrepareReport(reportViewer);

                    reportViewer.RefreshReport();
                    _viewer.Child = reportViewer;
                }));
            }
        }

        protected abstract void PrepareReport(ReportViewer reportViewer);


    }
}